package com.myopen.converter;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;

public class ListConverter<T> {

	public List<T> list;
	public Page<T> page;
	public String[] dicTypeKeys;//字段名称
	public String[] dicTypes;//字典名称，数量必须与dicTypeKeys一样
	public String[] mapTypes;
	
	public ListConverter(List<T> list,String[] dicTypeKeys,String[] dicTypes) { 
		this.list=list;
		this.dicTypeKeys=dicTypeKeys;
		this.dicTypes=dicTypes;
	}
	
	public ListConverter(Page<T> page,String[] dicTypeKeys,String[] dicTypes) {
		this.page=page;
		this.list=page.getList();
		this.dicTypeKeys=dicTypeKeys;
		this.dicTypes=dicTypes;
	}
	
	public ListConverter(Page<T> page,String[] dicTypeKeys,String[] dicTypes,String[] mapTypes) {
		this.page=page;
		this.list=page.getList();
		this.dicTypeKeys=dicTypeKeys;
		this.dicTypes=dicTypes;
		this.mapTypes=mapTypes;
	}
	
	public List<T> getList() {
		
		for (T t : list) {
			t=new ObjectConverter<T>(t, dicTypeKeys, dicTypes, mapTypes).getObject();
		}
		
		return list;
	}
	
	public Page<T> getPage(){
		List<T> list=getList();
		return new Page<>(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow());
	}
}
